import {RECEIVE_ADDRESS,RECEIVE_CATEGORYS,RECEIVE_SHOPS,RECEIVE_USER_INFO,RESET_USER_INFO} from './mutation-types'

import { reqAddress,reqCategory,reqShops } from '../api/index.js'
export default {
    // 3个方法
    //方法一  触发address
    //方法二  触发categorys
    //方法三  触发shops
    // 获取地址
    async getAddress({commit,state}){
        let {latitude,longitude}=state
        // data={
        //     latitude, 
        //     longitude
        // }
        let params=latitude+','+longitude
        let result= await reqAddress(params)
        console.log(result);
        
        // commit 指的是mutations里面的方法
       commit(RECEIVE_ADDRESS,{address:result.data})
    },
    // 获取产品分类
    async getCategorys({commit}){
        let result= await reqCategory()
        commit(RECEIVE_CATEGORYS,{categorysx:result.data})
    },
    // 获取商家
    async getShops({commit,state}){
        let {latitude,longitude}=state
        let result=await reqShops({latitude,longitude})
        commit(RECEIVE_SHOPS,{shops:result.data})
    },
    // 获取个人信息
    recordUser({commit},user){
        commit(RECEIVE_USER_INFO,{userInfo:user})
    }
}